# -*- coding: utf-8 -*-

# Define your item pipelines here
#
# Don't forget to add your pipeline to the ITEM_PIPELINES setting
# See: https://doc.scrapy.org/en/latest/topics/item-pipeline.html
import os
import json


class Xueqiu2Pipeline(object):
    def process_item(self, item, spider):
        path = './data'

        if not os.path.exists(path):
            os.mkdir(path)
        with open(path + '/' + 'data.txt', 'a') as f:
            data = json.dumps(item, ensure_ascii=False)
            f.write(data)
            f.write('\n')
            f.write('\n')
        return item


    def open_spider(self, spider):
        print('爬虫启动')

    def close_spider(self, spider):
        print('爬虫结束')